#script2302.py - HD Presentation (Speed Increased)
#Written by Blum and Bresnahan
# 
##########################################
#
##### Import Functions & Variables #######
#
from os import listdir, system	#Import from OS module
#
				#Import from PyGame Library
from pygame import event, font, display, image, init, transform
#
from sys import exit		#Import from System module
#
from pygame.locals import *	#Load PyGame constants
#
init()				#Initialize PyGame
#
# Set up Picture  Variables ######################
# 
PictureDirectory='/home/pi/pictures'
PictureFileExtension='.jpg'
PictureDisk='/dev/sda1'
#
# Mount the Picture Drive ########################
#
Command="sudo umount " + PictureDisk + " 2>/dev/null"
system(Command)
Command="sudo mount -t vfat " + PictureDisk + " " + PictureDirectory
system(Command)
#
# Set up Presentation Text #######################
#
# Color #
#
RazPiRed=210,40,82
#
# Font #
#
DefaultFont='/usr/share/fonts/truetype/freefont/FreeSans.ttf'
PrezFont=font.Font(DefaultFont,60)
#
# Text #
#
IntroText1="Our Trip to the"
IntroText2="Raspberry Capital of the World"
IntroText1=PrezFont.render(IntroText1,True,RazPiRed)
IntroText2=PrezFont.render(IntroText2,True,RazPiRed)
#
# Set up the Presentation Screen ################
#
ScreenColor=Gray= 125,125,125
#
ScreenFlag=FULLSCREEN | NOFRAME | DOUBLEBUF
PrezScreen=display.set_mode((0,0),ScreenFlag)
#
PrezScreenRect=PrezScreen.get_rect()
CenterScreen=PrezScreenRect.center
AboveCenterScreen=CenterScreen[0],CenterScreen[1]-100
#
PrezScreenSize=PrezScreen.get_size()
Scale=PrezScreenSize[0]-20,PrezScreenSize[1]-20
#
###### Run the Presentation  #######################################
#
while True:
	# Introduction Screen ##############################
	#
	PrezScreen.fill(ScreenColor)
	#
	# Put Intro Text Line 1 above Center of Screen
	IntroText1Location=IntroText1.get_rect()
	IntroText1Location.center=AboveCenterScreen
	PrezScreen.blit(IntroText1,IntroText1Location)
	#
	# Put Intro Text Line 2 at Center of Screen
	IntroText2Location=IntroText2.get_rect()
	IntroText2Location.center=CenterScreen
	PrezScreen.blit(IntroText2,IntroText2Location)
	#
	display.update()
	#
	#Get HD Pictures ###################################
	#
	for Picture in listdir(PictureDirectory):
		if Picture.endswith(PictureFileExtension):
			Picture=PictureDirectory + '/' + Picture
			#
			Picture=image.load(Picture)
			#
			Continue=0
			# Show next Picture with Mouse
			while Continue == 0:
				for Event in event.get():
					if Event.type == MOUSEBUTTONDOWN:
						Continue=1
					if Event.type in (QUIT,KEYDOWN):
						Command="sudo umount " + PictureDisk
						system(Command)
						exit()
			#
			# If Picture is bigger than screen, scale it down.
			if Picture.get_size() > PrezScreenSize:
				Picture = transform.scale(Picture,Scale)
			#
			PictureLocation=Picture.get_rect()  #Current location 
			PictureLocation.center=CenterScreen #Put picture in center of screen
			#
			#Display HD Images to Screen #################3
			PrezScreen.fill(ScreenColor)
			PrezScreen.blit(Picture,PictureLocation)
			display.update()
		#
		# Quit with Keyboard if Desired
		for Event in event.get():
			if Event.type in (QUIT,KEYDOWN):
				Command="sudo umount " + PictureDisk
				system(Command)
				exit()
#


